package com.yunxi.core.util;

import org.apache.commons.beanutils.PropertyUtils;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.InvocationTargetException;
import java.text.ParseException;
import java.util.*;

public class WgrString
{
	public static final int	ADD_BACK	= 1;

	public static final int	ADD_FORE	= 2;
	
	private final static char[] chr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
        'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
        'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T',
        'U', 'V', 'W', 'X', 'Y', 'Z'};
	
	private final static char[] numchr = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
	
	public static String getISO_UTF(String name)
	{
		String n = "";
		try
		{
			n = new String(name.getBytes("ISO-8859-1"), "UTF-8");
		} catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
		return n;
	}

	public static String getISO_GBK(String name)
	{
		String n = "";
		try
		{
			n = new String(name.getBytes("ISO-8859-1"), "GBK");
		} catch (UnsupportedEncodingException e)
		{
			e.printStackTrace();
		}
		return n;
	}

	public static String gbk2utf8(String chenese)
	{
		char c[] = chenese.toCharArray();
		byte[] fullByte = new byte[3 * c.length];
		for (int i = 0; i < c.length; i++)
		{
			int m = (int) c[i];
			String word = Integer.toBinaryString(m);

			StringBuffer sb = new StringBuffer();
			int len = 16 - word.length();
			// ����
			for (int j = 0; j < len; j++)
			{
				sb.append("0");
			}
			sb.append(word);
			sb.insert(0, "1110");
			sb.insert(8, "10");
			sb.insert(16, "10");

			// System.out.println(sb.toString());

			String s1 = sb.substring(0, 8);
			String s2 = sb.substring(8, 16);
			String s3 = sb.substring(16);

			byte b0 = Integer.valueOf(s1, 2).byteValue();
			byte b1 = Integer.valueOf(s2, 2).byteValue();
			byte b2 = Integer.valueOf(s3, 2).byteValue();
			byte[] bf = new byte[3];
			bf[0] = b0;
			fullByte[i * 3] = bf[0];
			bf[1] = b1;
			fullByte[i * 3 + 1] = bf[1];
			bf[2] = b2;
			fullByte[i * 3 + 2] = bf[2];
		}
		return new String(fullByte);
	}

	/**
	 * ����ĸ��д ����Сд
	 * @param tablename
	 * @return
	 */
	public static String firstUpper(String tablename)
	{
		if(tablename!=null&&tablename.length()>1)
		{
			String head = tablename.substring(0, 1);
			String body = tablename.substring(1);
			head = head.toUpperCase();
			return head + body.toLowerCase();
		}
		return tablename;
	}
	
	/**
	 * ����ĸ��д ���治��
	 * @param tablename
	 * @return
	 */
	public static String firstUpper2(String tablename)
	{
		if(tablename!=null&&tablename.length()>1)
		{
			String head = tablename.substring(0, 1);
			String body = tablename.substring(1);
			head = head.toUpperCase();
			return head + body;
		}
		return tablename;
	}

	public static String firstLow(String tablename)
	{
		if(tablename!=null&&tablename.length()>1)
		{
			String head = tablename.substring(0, 1);
			String body = tablename.substring(1);
			head = head.toLowerCase();
			return head + body;
		}
		return tablename;
	}

	public static String strCut(String colum, int len)
	{
		colum = colum.trim();
		if ((colum.length() > len) && (colum.length() != len + 1))
			colum = colum.substring(0, len) + "...";
		return colum;
	}

	public static String strCutCn(String str, int num)
	{
		String myStr = "";
		if(!WgrString.isEmpty(str)){
    		int strl1 = 0;
    		int forNum = 0;
    		int alli = 0;
    		int strLen = str.length();
    		for (int i = 0; i < strLen; ++i)
    		{
    			if (num == Math.floor(forNum / 2.0F)) break;
    			if (str.substring(i, i + 1).getBytes().length > 1)
    			{
    				forNum += 2;
    			}
    			else
    			{
    				++strl1;
    				++forNum;
    			}
    			++alli;
    		}
    		
    		if (strLen > num){
    			if(strLen-1==num){
    				myStr = str.substring(0, --alli) + "...";
    			}else{
    				myStr = str.substring(0, alli) + "...";
    			}
    		}
    		else
    		{
    			myStr = str.substring(0, strLen);
    		}
		}
		return myStr;
	}

	public static String strApp(String[] s, String cut)
	{
		StringBuffer ss = new StringBuffer();

		for (int i = 0; i < s.length; ++i)
		{
			if (i == s.length - 1)
			{
				ss.append(s[i]);
			}
			else
			{
				ss.append(s[i] + cut);
			}
		}
		return ss.toString();
	}

	public static String[] strUnapp(String s, String delim)
	{
		/* 143 */String[] ss = (String[]) null;
		/* 144 */if (s != null)
		{
			/* 146 */ss = getTokens(s, delim);
		}
		/* 148 */return ss;
	}

	private static String[] getTokens(String test, String delim)
	{
		/* 154 */Collection tokens = new ArrayList();
		/* 155 */StringTokenizer tokenizer = new StringTokenizer(test, delim);
		/* 156 */while (tokenizer.hasMoreElements())
		{
			/* 158 */tokens.add(tokenizer.nextToken());
		}

		/* 161 */return ((String[]) tokens.toArray(new String[0]));
	}

	public static String filerStr(String param)
	{
		/* 169 */if (param == null)
		{
			/* 171 */return (param = "");
		}
		/* 173 */return param;
	}

	public static String filerStr(String param, String defaul)
	{
		/* 181 */if (param == null)
		{
			/* 183 */return (param = defaul);
		}
		/* 185 */return param;
	}

	public static String padding(String str, int length, char c)
	{
		/* 194 */int len = length - str.length();

		/* 196 */for (int i = 0; i < len; ++i)
		{
			/* 198 */str = c + str;
		}
		/* 200 */return str;
	}

	public static String getClassPath()
	{
		/* 210 */String url = WgrString.class.getResource(
				"/applicationContext.xml")
		/* 211 */.toString();

		/* 213 */String tag = "file:/";
		/* 214 */int index = url.indexOf(tag);
		/* 215 */if (index >= 0)
		{
			/* 217 */url = url.substring(index + tag.length());
		}
		/* 219 */index = url.indexOf(":/");

		/* 221 */index = url.indexOf("/applicationContext.xml");
		/* 222 */if (index >= 0)
		{
			/* 224 */url = url.substring(0, index);
		}
		/* 226 */return url;
	}

	public static String getAppPath()
	{
		/* 236 */String url = WgrString.class.getResource(
				"/applicationContext.xml")
		/* 237 */.toString();

		/* 239 */String tag = "file:/";
		/* 240 */int index = url.indexOf(tag);
		/* 241 */if (index >= 0)
		{
			/* 243 */url = url.substring(index + tag.length());
		}
		/* 245 */index = url.indexOf(":/");

		/* 247 */index = url.indexOf("/WEB-INF");
		/* 248 */if (index >= 0)
		{
			/* 250 */url = url.substring(0, index);
		}
		/* 252 */return url;
	}

	public static String getCutduanstr(String content, String pflag,
                                       String cflag, String sflag, String prefix, String suffix)
	{
		/* 263 */int beginindex = 0;
		/* 264 */int endindex = 0;
		do
		{
			/* 268 */beginindex = content.indexOf(pflag);

			/* 270 */if (beginindex == -1) continue;
			/* 272 */endindex = content.indexOf(sflag, beginindex + 1);
			/* 273 */if (endindex == -1) continue;
			/* 275 */String cutString = content.substring(beginindex,
			/* 276 */endindex + 1);
			/* 277 */String pluginId = cutString.substring(
			/* 278 */cutString.lastIndexOf(cflag) + 1, cutString
			/* 279 */.lastIndexOf(sflag));
			/* 280 */content = content.replaceAll(cutString,
			/* 281 */prefix + pluginId + suffix);
		}

		/* 284 */while (content.indexOf(pflag) != -1);

		/* 286 */return content;
	}

	public static String newString(String value, int length)
	{
		/* 305 */StringBuffer buffer = new StringBuffer();
		/* 306 */if (value == null)
		{
			/* 308 */return null;
		}
		/* 310 */for (int i = 0; i < length; ++i)
		{
			/* 312 */buffer.append(value);
		}
		/* 314 */return buffer.toString();
	}

	public static String setChar(char chr, int totalLen)
	{
		/* 330 */return setChar("", chr, totalLen, 2);
	}

	public static String setChar(String str, char chr, int totalLen)
	{
		/* 347 */return setChar(str, chr, totalLen, 2);
	}

	public static String setChar(String str, char chr, int totalLen,
                                 int position)
	{
		/* 367 */if ((totalLen < 0) || (str == null)) return str;
		/* 368 */int sLen = str.length();
		/* 369 */String ret = str;
		/* 370 */for (int i = 0; i < totalLen - sLen; ++i)
		{
			/* 372 */if (position == 1)
			{
				/* 374 */ret = ret + chr;
			}
			else
			{
				/* 378 */ret = chr + ret;
			}
		}
		/* 381 */return ret;
	}

	public static boolean isLetterString(String str)
	{
		/* 395 */if (str == null) return false;
		/* 396 */for (int i = 0; i < str.length(); ++i)
		{
			/* 398 */if (!(Character.isLetter(str.charAt(i)))) return false;
		}
		/* 400 */return true;
	}

	public static boolean isLetterOrDigitString(String str)
	{
		/* 414 */if (str == null) return false;
		/* 415 */for (int i = 0; i < str.length(); ++i)
		{
			/* 417 */if (!(Character.isLetterOrDigit(str.charAt(i))))
				return false;
		}
		/* 419 */return true;
	}

	public static String[] sort(String[] strs)
	{
		/* 431 */int i = 0;
		int j = 1;
		int len = strs.length;
		/* 432 */if (len <= 1) return strs;

		/* 434 */String strTmp = null;
		/* 435 */for (i = 0; i < len - 1; ++i)
		{
			/* 437 */for (j = i + 1; j < len; ++j)
			{
				/* 439 */if (strs[i].compareTo(strs[j]) >= 0) continue;
				/* 441 */strTmp = strs[i];
				/* 442 */strs[i] = strs[j];
				/* 443 */strs[j] = strTmp;
			}
		}

		/* 447 */return strs;
	}

	public static String copyString(String str, int copyTimes)
	{
		/* 461 */StringBuffer buffer = new StringBuffer();
		/* 462 */if (str == null)
		{
			/* 463 */return null;
		}
		/* 465 */for (int i = 0; i < copyTimes; ++i)
		{
			/* 466 */buffer.append(str);
		}
		/* 468 */return buffer.toString();
	}

	public static int indexOf(String str, String subStr, int startIndex,
                              int occurrenceTimes)
	{
		/* 485 */int foundCount = 0;
		/* 486 */int index = startIndex;
		/* 487 */int substrLength = subStr.length();
		/* 488 */if (occurrenceTimes <= 0)
		/* 489 */return -1;
		/* 490 */if (str.length() - 1 < startIndex)
		/* 491 */return -1;
		/* 492 */if (subStr.equals(""))
		/* 493 */return 0;
		/* 494 */while (foundCount < occurrenceTimes)
		{
			/* 495 */index = str.indexOf(subStr, index);
			/* 496 */if (index == -1)
			/* 497 */return -1;
			/* 498 */++foundCount;
			/* 499 */index += substrLength;
		}
		/* 501 */return (index - substrLength);
	}

	public static int indexOf(String str, String subStr, int occurrenceTimes)
	{
		/* 517 */return indexOf(str, subStr, 0, occurrenceTimes);
	}

	public static int indexOf(String str, String subStr, int fromIndex,
                              boolean caseSensitive)
	{
		/* 534 */if (!(caseSensitive))
		{
			/* 535 */return str.toLowerCase().indexOf(subStr.toLowerCase(),
					fromIndex);
		}
		/* 537 */return str.indexOf(subStr, fromIndex);
	}

	public static String replace(String str, String searchStr,
                                 String replaceStr, boolean caseSensitive)
	{
		/* 558 */String result = "";
		/* 559 */int i = 0;
		/* 560 */int j = 0;
		/* 561 */if (str == null)
		{
			/* 562 */return null;
		}
		/* 564 */if (str.equals(""))
		{
			/* 565 */return "";
		}
		/* 567 */if ((searchStr == null) || (searchStr.equals("")))
		{
			/* 568 */return str;
		}
		/* 570 */if (replaceStr == null)
		{
			/* 571 */replaceStr = "";
		}
		/* 573 */while ((j = indexOf(str, searchStr, i, caseSensitive)) > -1)
		{
			/* 574 */result = result + str.substring(i, j) + replaceStr;
			/* 575 */i = j + searchStr.length();
		}
		/* 577 */result = result + str.substring(i, str.length());
		/* 578 */return result;
	}

	public static String replace(String str, String searchStr, String replaceStr)
	{
		/* 598 */return replace(str, searchStr, replaceStr, true);
	}

	public static String replace(String str, char searchChar, String replaceStr)
	{
		/* 618 */return replace(str, searchChar + "", replaceStr, true);
	}

	public static String replace(String str, int beginIndex, String replaceStr)
	{
		/* 632 */String result = null;
		/* 633 */if (str == null)
		{
			/* 634 */return null;
		}
		/* 636 */if (replaceStr == null)
		{
			/* 637 */replaceStr = "";
		}
		/* 639 */result = str.substring(0, beginIndex) + replaceStr +
		/* 640 */str.substring(beginIndex + replaceStr.length());
		/* 641 */return result;
	}

	public static String[] split(String originalString, int splitByteLength)
	{
		/* 670 */ArrayList vector = new ArrayList();
		/* 671 */String strText = "";
		/* 672 */byte[] arrByte = (byte[]) null;
		/* 673 */int intStartIndex = 0;
		/* 674 */int intEndIndex = 0;
		/* 675 */int index = 0;
		/* 676 */int fixCount = 0;
		/* 677 */String[] arrReturn = (String[]) null;

		/* 679 */if (originalString == null)
		{
			/* 680 */return new String[0];
		}
		/* 682 */if (originalString.equals(""))
		{
			/* 683 */return new String[0];
		}
		/* 685 */if (originalString.trim().equals(""))
		{
			/* 686 */return new String[]
			{ "" };
		}
		/* 688 */if (splitByteLength <= 1)
		{
			/* 689 */return new String[]
			{ originalString };
		}

		/* 692 */arrByte = originalString.getBytes();
		/* 693 */intEndIndex = 0;
		while (true)
		{
			/* 696 */intStartIndex = intEndIndex;
			/* 697 */intEndIndex = intStartIndex + splitByteLength;

			/* 699 */if (intStartIndex >= arrByte.length)
			{
				break;
			}

			/* 703 */if (intEndIndex > arrByte.length)
			{
				/* 704 */intEndIndex = arrByte.length;
				/* 705 */strText = new String(arrByte, intStartIndex,
						intEndIndex - intStartIndex);
				/* 706 */vector.add(strText);
				/* 707 */break;
			}

			/* 710 */fixCount = 0;
			/* 711 */strText = new String(arrByte, intStartIndex,
					intEndIndex - intStartIndex);
			/* 712 */byte[] bytes = strText.getBytes();
			/* 713 */if (bytes.length < splitByteLength)
			{
				/* 714 */intEndIndex = intStartIndex + bytes.length;
			}
			/* 716 */for (index = intEndIndex - 1; index >= intStartIndex; --index)
			{
				/* 717 */if (arrByte[index] == bytes[(index - intStartIndex)])
					break;
				/* 719 */++fixCount;
				continue;

			}

			/* 727 */if (fixCount > 0)
			{
				/* 728 */if (fixCount >= intEndIndex)
				{
					/* 729 */fixCount = 0;
					/* 730 */
                    System.out
							.println("split length " + splitByteLength + " is too small.");
				}
				/* 732 */intEndIndex -= fixCount;

				/* 735 */strText = new String(arrByte, intStartIndex,
						intEndIndex - intStartIndex);
			}
			/* 737 */vector.add(strText);
		}

		/* 740 */arrReturn = new String[vector.size()];
		/* 741 */vector.toArray(arrReturn);

		/* 743 */return arrReturn;
	}

	public static String[] split(String originalString, String delimiterString)
	{
		/* 772 */int index = 0;
		/* 773 */String[] returnArray = (String[]) null;
		/* 774 */int length = 0;

		/* 776 */if ((originalString == null) || (delimiterString == null) || (originalString
				.equals("")))
		{
			/* 777 */return new String[0];
		}

		/* 780 */if ((originalString.equals("")) || (delimiterString
				.equals("")) ||
		/* 781 */(originalString.length() < delimiterString.length()))
		{
			/* 782 */return new String[]
			{ originalString };
		}

		/* 785 */String strTemp = originalString;
		/* 786 */while ((strTemp != null) && (!(strTemp.equals(""))))
		{
			/* 787 */index = strTemp.indexOf(delimiterString);
			/* 788 */if (index == -1)
			{
				break;
			}
			/* 791 */++length;
			/* 792 */strTemp = strTemp.substring(index + delimiterString
					.length());
		}
		/* 794 */returnArray = new String[++length];

		/* 796 */for (int i = 0; i < length - 1; ++i)
		{
			/* 797 */index = originalString.indexOf(delimiterString);
			/* 798 */returnArray[i] = originalString.substring(0, index);
			/* 799 */originalString = originalString
					.substring(index + delimiterString.length());
		}
		/* 801 */returnArray[(length - 1)] = originalString;
		/* 802 */return returnArray;
	}

	public static String rightTrim(String str)
	{
		/* 814 */if (str == null)
		{
			/* 815 */return "";
		}
		/* 817 */int length = str.length();
		/* 818 */for (int i = length - 1; i >= 0; --i)
		{
			/* 819 */if (str.charAt(i) != ' ')
			{
				break;
			}
			/* 822 */--length;
		}
		/* 824 */return str.substring(0, length);
	}

	public static String leftTrim(String str)
	{
		/* 836 */if (str == null)
		{
			/* 837 */return "";
		}
		/* 839 */int start = 0;
		/* 840 */int i = 0;
		for (int n = str.length(); i < n; ++i)
		{
			/* 841 */if (str.charAt(i) != ' ')
			{
				break;
			}
			/* 844 */++start;
		}
		/* 846 */return str.substring(start);
	}

	public static String absoluteTrim(String str)
	{
		String result = replace(str, " ", "");
		return result;
	}

	public static String lowerCase(String str, int beginIndex, int endIndex)
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append(str.substring(0, beginIndex));
		buffer.append(str.substring(beginIndex, endIndex)
				.toLowerCase());
		buffer.append(str.substring(endIndex));
		return buffer.toString();
	}

	public static String upperCase(String str, int beginIndex, int endIndex)
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append(str.substring(0, beginIndex));
		buffer.append(str.substring(beginIndex, endIndex)
				.toUpperCase());
		buffer.append(str.substring(endIndex));
		return buffer.toString();
	}

	public static String lowerCaseFirstChar(String iString)
	{
		String newString = iString.substring(0, 1).toLowerCase() + iString
				.substring(1);
		return newString;
	}

	public static String upperCaseFirstChar(String iString)
	{
		String newString = iString.substring(0, 1).toUpperCase() + iString
				.substring(1);
		return newString;
	}

	public static int timesOf(String str, String subStr)
	{
		int foundCount = 0;
		if (subStr.equals(""))
		{
			/* 937 */return 0;
		}
		/* 939 */int fromIndex = str.indexOf(subStr);
		/* 940 */while (fromIndex != -1)
		{
			/* 941 */++foundCount;
			/* 942 */fromIndex = str.indexOf(subStr, fromIndex + subStr
					.length());
		}
		/* 944 */return foundCount;
	}

	public static int timesOf(String str, char ch)
	{
		/* 957 */int foundCount = 0;
		/* 958 */int fromIndex = str.indexOf(ch);
		/* 959 */while (fromIndex != -1)
		{
			/* 960 */++foundCount;
			/* 961 */fromIndex = str.indexOf(ch, fromIndex + 1);
		}
		/* 963 */return foundCount;
	}

	public static Map toMap(String str, String splitString)
	{
		/* 977 */Map map = Collections.synchronizedMap(new HashMap());
		/* 978 */String[] values = split(str, splitString);
		/* 979 */for (int i = 0; i < values.length; ++i)
		{
			/* 980 */String tempValue = values[i];
			/* 981 */int pos = tempValue.indexOf("=");
			/* 982 */String key = "";
			/* 983 */String value = "";
			/* 984 */if (pos > -1)
			{
				/* 985 */key = tempValue.substring(0, pos);
				/* 986 */value = tempValue.substring(pos + splitString
						.length());
			}
			else
			{
				/* 989 */key = tempValue;
			}
			/* 991 */map.put(key, value);
		}
		/* 993 */return map;
	}

	public static String native2ascii(String str)
	{
		/* 1004 */char[] ca = str.toCharArray();
		/* 1005 */StringBuffer buffer = new StringBuffer(ca.length * 6);
		/* 1006 */for (int x = 0; x < ca.length; ++x)
		{
			/* 1007 */char a = ca[x];
			/* 1008 */if (a > 255)
			{
				/* 1009 */buffer.append("\\u").append(Integer.toHexString(a));
			}
			else
			{
				/* 1012 */buffer.append(a);
			}
		}
		/* 1015 */return buffer.toString();
	}

	public static String bindParam(String sql, String param)
	{
		/* 1022 */String[] str = param.split(",");
		/* 1023 */for (int i = 0; i < str.length; ++i)
		{
			/* 1024 */if (sql.indexOf("[" + i + "]", 0) != -1)
			/* 1025 */sql = sql.replace("[" + i + "]", str[i]);
		}
		/* 1027 */return sql;
	}

	public static String strAppSql(String[] s, String cut)
	{
		StringBuffer ss = new StringBuffer();

		if (s != null)
		{
		    for (int i = 0; i < s.length; ++i)
			{
				if (i == s.length - 1)
				{
					ss.append("'" + s[i] + "'");
				}
				else
				{
					ss.append("'" + s[i] + "'" + cut);
				}
			}
		}
		return ss.toString();
	}

	public static String numAppSql(String[] s, String cut)
	{
		/* 1052 */StringBuffer ss = new StringBuffer();

		/* 1054 */if (s != null)
		{
			/* 1055 */for (int i = 0; i < s.length; ++i)
			{
				/* 1057 */if (i == s.length - 1)
				{
					/* 1059 */ss.append(s[i]);
				}
				else
				{
					/* 1063 */ss.append(s[i] + cut);
				}
			}
		}
		/* 1067 */return ss.toString();
	}

	public static String list2str(List list, int index, String property)
	{
		/* 1072 */String temp = "";
		/* 1073 */if ((((list != null) ? 1 : 0) & ((list.size() > 0) ? 1 : 0)) != 0)
		{
			try
			{
				/* 1077 */for (int i = 0; i < list.size(); ++i)
				{
					/* 1079 */Object[] o = (Object[]) list.get(i);

					/* 1081 */temp = temp + PropertyUtils.getSimpleProperty(
							o[index], property) + ",";
				}
			} catch (IllegalAccessException e)
			{
				/* 1086 */e.printStackTrace();
			} catch (InvocationTargetException e)
			{
				/* 1090 */e.printStackTrace();
			} catch (NoSuchMethodException e)
			{
				/* 1094 */e.printStackTrace();
			}
		}
		/* 1097 */return temp;
	}

	public static String list2str(List list, String property)
	{
		/* 1102 */String temp = "";
		/* 1103 */if ((((list != null) ? 1 : 0) & ((list.size() > 0) ? 1 : 0)) != 0)
		{
			try
			{
				/* 1107 */for (int i = 0; i < list.size(); ++i)
				{
					/* 1109 */Object o = list.get(i);

					/* 1111 */temp = temp + PropertyUtils.getSimpleProperty(o,
							property) + ",";
				}
			} catch (IllegalAccessException e)
			{
				/* 1116 */e.printStackTrace();
			} catch (InvocationTargetException e)
			{
				/* 1120 */e.printStackTrace();
			} catch (NoSuchMethodException e)
			{
				/* 1124 */e.printStackTrace();
			}
		}
		/* 1127 */return temp;
	}

	public static List list2Obj(List list, int index)
	{
		/* 1138 */List temp = new ArrayList();
		/* 1139 */if ((((list != null) ? 1 : 0) & ((list.size() > 0) ? 1 : 0)) != 0)
		{
			/* 1141 */for (int i = 0; i < list.size(); ++i)
			{
				/* 1143 */Object[] o = (Object[]) list.get(i);

				/* 1147 */temp.add(o[index]);
			}
		}
		/* 1150 */return temp;
	}

	public static Map list2map(List list, String key, String value)
	{
		Map temp = new HashMap();
		if ((list != null) && (list.size() > 0))
		{
			try
			{
				for (int i = 0; i < list.size(); ++i)
				{
					Object o = list.get(i);
					Object key_ = PropertyUtils.getSimpleProperty(o,
							key);
					Object value_ = PropertyUtils.getSimpleProperty(
							o, value);

					temp.put(key_.toString(), value_);
				}
			} catch (IllegalAccessException e)
			{
				e.printStackTrace();
			} catch (InvocationTargetException e)
			{
				e.printStackTrace();
			} catch (NoSuchMethodException e)
			{
				e.printStackTrace();
			}
		}
		return temp;
	}

	public static String[] list2Array(List list, String property)
	{
		String[] temp = new String[list.size()];

		if ((((list != null) ? 1 : 0) & ((list.size() > 0) ? 1 : 0)) != 0)
		{
			try
			{
				for (int i = 0; i < list.size(); ++i)
				{
					/* 1195 */Object o = list.get(i);

					/* 1197 */temp[i] = PropertyUtils.getSimpleProperty(o,
							property).toString();
				}
			} catch (IllegalAccessException e)
			{
				/* 1202 */e.printStackTrace();
			} catch (InvocationTargetException e)
			{
				/* 1206 */e.printStackTrace();
			} catch (NoSuchMethodException e)
			{
				/* 1210 */e.printStackTrace();
			}
		}
		/* 1213 */return temp;
	}

	public static String decode(String value, String rule, String defaults)
	{
		String[] rules = rule.split(";");
		String revalue = "";
		if (rules.length > 0)
		{
			for (int i = 0; i < rules.length; ++i)
			{
				String[] keyvalue = rules[i].split(",");

				if (!(value.equals(keyvalue[0]))) continue;
				revalue = keyvalue[1];
			}
		}

		if (revalue.equals(""))
		{
			revalue = defaults;
		}
		return revalue;
	}

	public static String trimToEmpty(String paramString)
	{
		return ((paramString == null) ? "" : paramString.trim());
	}
	
	public static boolean isBlank(String paramString)
    {
      int i;
      if (paramString != null)
      {
          if ((i = paramString.length()) != 0)
          {
                for (int j = 0; j < i; ++j)
                {
                    if (!(Character.isWhitespace(paramString.charAt(j))))
                    {
                        return false;
                    }
                }
          }
      }
      return true;
    }
	
	public static String allLow(String tablename) //�ֶε�һ��͵ڶ���ĸСд������Ĳ���
	{
		String s=null;
		if(tablename!=null && tablename!=""){
			s=tablename.toLowerCase();
			s=s.replaceAll("_", "");
		}
		return s;
	}
	
	public static String allLowOnly(String tablename) //�ֶε�һ��͵ڶ���ĸСд������Ĳ���
    {
        String s=null;
        if(tablename!=null && tablename!=""){
            s=tablename.toLowerCase();
        }
        return s;
    }
	
	public static String getFileNameForUrl(String weburl){
	    String web = weburl;
	    if(isNotEmpty(web)&&web.indexOf(".")!=-1&&web.indexOf("/")!=-1){
	        web = web.substring(web.lastIndexOf("/")+1);
        }
	    return web;
	}
	
	public static void main(String[] args) throws ParseException
	{
		String key = "erp:1010:20181221:003";

		if(key.contains("_")){
			System.out.println(key.split("_")[1]);
		}else{
			System.out.println(key.split(":")[1]);
		}

		String key2 = "erp:1010:FH-2019-01-13-0072";

		if(key2.contains("-")){
			String aaa = key2.replaceAll("-","");
			System.out.println(aaa.split(":")[2].substring(2,10));
			System.out.println(aaa.split(":")[2].substring(10));
		}else{
		}

		String key3 = "20181221003";
		System.out.println(key3.substring(0,8));
	}
	
	public static String toEmpty(Object obj) {
		if (null == obj) {
			return "";
		}
		return String.valueOf(obj);
	}
	
	public static String getDeployPath()
    {
        String path = WgrString.class.getResource("/spring/applicationContext.xml").toString();//Excel�ļ�URL

        int index = path.indexOf("WEB-INF/classes/spring/applicationContext.xml");
        if(index >= 0){         
            path = path.substring(0,index); 
        }
        String tag = "file:";
        index = path.indexOf(tag);
        if(index >= 0){
            path = path.substring(index+tag.length());
        }
        index = path.indexOf(":/");
        if(index >= 0){         
            path = path.substring(1);
        }
        
        return path;
    }
	
	public static String mapReplaceContent(String content, Map map)
	{
	    if(map!=null){
    	    Iterator it = map.entrySet().iterator();
            while (it.hasNext()) { 
                Map.Entry entry = (Map.Entry) it.next();
                String key = (String)entry.getKey();
                String value = (String)entry.getValue();
                content+=content.replaceAll(key, value);
            } 
	    }
	    return content;
	}
	
	public static boolean isEmpty(String input) {
        return input == null || input.trim().length() == 0;
    }
	
	public static boolean isNotEmpty(String input) {
        return input != null && (!input.equals(""));
    }
	
	public static boolean isNotEmpty(Date input) {
        return input != null;
    }

    /**
     */
    public static boolean isEmpty(Object obj) {
        return obj == null || obj.toString().length() == 0;
    }

    /**
     * �жϼ����Ƿ�Ϊ��
     *
     * @param lst ĳ�ַ�
     * @return ���򷵻�true�����򷵻�false
     */
    public static boolean isEmpty(List lst) {
        return lst == null || lst.size() == 0;
    }
    
    /**
     *
     * @param str ĳ�ַ�
     */
    public static boolean isEmptyAfterTrim(String str) {
        return str == null || str.trim().length() == 0;
    }
    
    /**
     *
     * @return String
     */
    public static String getRandomNumber() {
        return getRandomNumber(10);
    }
    
    /**
     *
     * @param length
     * @return String
     */
    public static String getRandomNumber(int length) {
        Random random = new Random();
        StringBuffer buffer = new StringBuffer();

        for (int i = 0; i < length; i++) {
            buffer.append(random.nextInt(10));
        }
        return buffer.toString();
    }

    /**
     * @param length ������
     * @return String
     */

    public static String getRandomChar(int length) {

        Random random = new Random();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < length; i++) {
            buffer.append(chr[random.nextInt(36)]);
        }
        return buffer.toString();
    }
    
    public static String getRandomNumChar(int length) {

        Random random = new Random();
        StringBuffer buffer = new StringBuffer();
        for (int i = 0; i < length; i++) {
            buffer.append(numchr[random.nextInt(10)]);
        }
        return buffer.toString();
    }

    /**
     *
     * @return String
     */
    public static String getRandomChar() {
        return getRandomChar(10);
    }
}